// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {ILendingManager} from "./interfaces/ILendingManager.sol";
import {FakeLending} from "./tests/FakeLending.sol";

abstract contract LendingManager is ILendingManager, ReentrancyGuard {
    using SafeERC20 for IERC20;

    function isAssetAllowed(address asset) public view virtual override returns (bool);
    function isLendingAllowed(address lending) public view virtual override returns (bool);

    constructor() {}

    function deposit(address lending, address token, uint256 amount) public override nonReentrant onlyProtocolTrader {
        require(isLendingAllowed(lending), "LendingManager: deposit: lending is not allowed");
        require(isAssetAllowed(token), "LendingManager: deposit: token is not allowed");
        IERC20(token).safeApprove(lending, amount);
        FakeLending(lending).deposit(token, amount);
    }

    function withdraw(address lending, address token, uint256 amount) public override nonReentrant onlyProtocolTrader {
        require(isLendingAllowed(lending), "LendingManager: withdraw: lending is not allowed");
        require(isAssetAllowed(token), "LendingManager: withdraw: token is not allowed");
        FakeLending(lending).withdraw(token, amount);
    }

    modifier onlyProtocolTrader() virtual;
}
